﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Digitalmes.Model.EquipmentManagement;
using Digitalmes.Model;

namespace Digitalmes.ViewModel.EquipmentManagement.ConsumableUsageVMs
{
    public partial class ConsumableUsageListVM : BasePagedListVM<ConsumableUsage_View, ConsumableUsageSearcher>
    {
        
        protected override IEnumerable<IGridColumn<ConsumableUsage_View>> InitGridHeader()
        {
            return new List<GridColumn<ConsumableUsage_View>>{
                
                this.MakeGridHeader(x => x.ConsumableUsage_Record).SetTitle(@Localizer["Page.关联维护记录"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_MaterialId).SetTitle(@Localizer["Page.耗材名称"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_MaterialName).SetTitle(@Localizer["Page.耗材名称"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_Specification).SetTitle(@Localizer["Page.规格"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_Quantity).SetTitle(@Localizer["Page.数量"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_Unit).SetTitle(@Localizer["Page.单位"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.ConsumableUsage_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<ConsumableUsage_View> GetSearchQuery()
        {
            var query = DC.Set<ConsumableUsage>()
                
                .CheckEqual(Searcher.RecordId, x=>x.RecordId)
                .CheckEqual(Searcher.MaterialId, x=>x.MaterialId)
                .CheckContain(Searcher.MaterialName, x=>x.MaterialName)
                .CheckContain(Searcher.Specification, x=>x.Specification)
                .CheckEqual(Searcher.Quantity, x=>x.Quantity)
                .CheckContain(Searcher.Unit, x=>x.Unit)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new ConsumableUsage_View
                {
				    ID = x.ID,
                    
                    ConsumableUsage_Record = x.Record.TenantCode,
                    ConsumableUsage_MaterialId = x.MaterialId,
                    ConsumableUsage_MaterialName = x.MaterialName,
                    ConsumableUsage_Specification = x.Specification,
                    ConsumableUsage_Quantity = x.Quantity,
                    ConsumableUsage_Unit = x.Unit,
                    ConsumableUsage_CreateTime = x.CreateTime,
                    ConsumableUsage_UpdateTime = x.UpdateTime,
                    ConsumableUsage_CreateBy = x.CreateBy,
                    ConsumableUsage_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class ConsumableUsage_View: ConsumableUsage
    {
        
        public string ConsumableUsage_Record { get; set; }
        public long? ConsumableUsage_MaterialId { get; set; }
        public string ConsumableUsage_MaterialName { get; set; }
        public string ConsumableUsage_Specification { get; set; }
        public decimal? ConsumableUsage_Quantity { get; set; }
        public string ConsumableUsage_Unit { get; set; }
        public DateTime? ConsumableUsage_CreateTime { get; set; }
        public DateTime? ConsumableUsage_UpdateTime { get; set; }
        public string ConsumableUsage_CreateBy { get; set; }
        public string ConsumableUsage_UpdateBy { get; set; }

    }

}